package com.tiancheng.trade.order.mq.consumer;

import com.tiancheng.trade.order.service.MessageSubscribeService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author kellen
 * @description 支付结算消息的处理者
 * @date 2025/03/18 09:24
 */
@Component
@RabbitListener(queues = "trade.payment.settle.message")
@Slf4j
public class PaymentSettleStatusMsgConsumer {

    @Resource
    private MessageSubscribeService messageSubscribeService;

    @RabbitHandler()
    public void handMessage(Message message) {
        try {
            String messageBody = new String(message.getBody());
            log.info("支付中心-订单结算消息消息回调：{}", messageBody);
            messageSubscribeService.handle(messageBody);
        } catch (Exception e) {
            log.error("支付消息回调消息失败：", e);
            throw e;
        }
    }
}
